<?php

declare (strict_types=1);
namespace App\Admin\Service;

use App\Event\UserRegistered;
use Hyperf\Di\Annotation\Inject;
use Psr\EventDispatcher\EventDispatcherInterface;
/**
 * 用户服务类
 * Class UserService
 * @package App\Admin\Service
 */
class UserService
{
    use \Hyperf\Di\Aop\ProxyTrait;
    use \Hyperf\Di\Aop\PropertyHandlerTrait;
    function __construct()
    {
        $this->__handlePropertyHandler(__CLASS__);
    }
    /**
     * @Inject()
     * @var EventDispatcherInterface
     */
    private $eventDispatcher;
    /**
     * 用户注册
     */
    public function register()
    {
        $user = ['id' => 1, 'name' => 'taylor', 'year' => 30];
        echo "用户注册成功.....";
        // 这里 dispatch(object $event) 会逐个运行监听该事件的监听器
        $this->eventDispatcher->dispatch(new UserRegistered($user));
    }
}